package com.st.springbootsse.listener;

import com.st.springbootsse.event.CustomEvent;
import com.st.springbootsse.utils.SseClient;
import jakarta.annotation.Resource;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author zhangli
 */
@Component
public class CustomListener {
    @Resource
    private SseClient sseClient;

    @EventListener
    public void onApplicationEvent(CustomEvent event) {
        System.out.println("CustomListener.onApplicationEvent()");
        System.out.println(event.getMsg());
        sseClient.sendMessage(event.getUid(), event.getMessageId(), event.getMsg());
    }
}
